<template>
    <div>
        <el-form :inline="true">
                <el-form-item label="一级分类">
                    <el-select v-model="c1Id" @change="handler1">
                        <el-option v-for="(c1, index) in store.state.category.c1List" :key="c1.id" :label="c1.name" :value="c1.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="二级分类">
                    <el-select v-model="c2Id" @change="handler2">
                        <el-option v-for="(c2, index) in store.state.category.c2List" :key="c2.id" :label="c2.name" :value="c2.id">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="三级分类">
                    <el-select v-model="c3Id" @change="handler3">
                        <el-option v-for="(c3, index) in store.state.category.c3List" :key="c3.id" :label="c3.name" :value="c3.id">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
    <!-- {{ state.category}} -->
    <!-- {{ state.category.c1List }} -->
    <!-- {{ store.state.category.c1List }} -->
    </div>
</template>

<script setup>
import { useStore } from 'vuex';
import { onMounted,ref } from 'vue'
let c1Id = ref('')
let c2Id = ref('')
let c3Id = ref('')
// let { dispatch,commit, state } = useStore();
const store = useStore(); // 该方法用于返回store 实例
onMounted(()=>{
    store.dispatch('category/getC1list')
})
const handler1 = () =>{
    store.dispatch('category/getC2list',c1Id.value)
    c2Id.value = ''
    c3Id.value = ''
}
const handler2 = () =>{
    c3Id.value = ''
    store.dispatch('category/getC3list',c2Id.value)
}
const handler3 = () =>{
    store.commit('category/setcategoryid',{c1Id:c1Id.value,c2Id:c2Id.value,c3Id:c3Id.value})
    // store.dispatch('category/getlistdata',{c1Id:c1Id.value,
    //     c2Id:c2Id.value,
    //     c3Id:c3Id.value})
}

</script>